package conference;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
/**
 * Reads a file and returns a string of the text in the file.
 * @author Taylor Zielske
 *
 */
public class WritetoFile {
	/**
	 * Gets contents from file
	 * @param file
	 * @return String
	 * @throws IOException
	 */
	public static String getFileContent(File file) throws IOException{
		FileReader in = new FileReader(file);
		StringWriter w= new StringWriter();
		char buffer[]=new char[2048];
		int n=0;
		while((n=in.read(buffer))!=-1){
			w.write(buffer, 0, n);
		}
		w.flush();
		in.close();
		return w.toString();
	}
	/**
	 * Writes the string of text to the file
	 * @param string
	 * @param file
	 * @throws IOException
	 */
	public static void toFileContent(String s,File file) throws IOException{
		FileWriter f=new FileWriter(file);
		f.write(s);
		f.flush();
		f.close();
	}
}
